package com.sample.sampleproj;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
//import android.os.Parcel;
//import android.os.Parcelable;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class ListViewActivity extends Activity {
	
	public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);// activity loads its UI from the XML file main.xml. 
       
       setContentView(R.layout.lva);
		//TextView textView = new TextView(this);
		//textView.setText("Main Activity");
		//setContentView(R.layout.list_item);
		Bundle extras = getIntent().getExtras();
		 String extraData=extras.getString("rest");
		// System.out.println(extras);
		//System.out.println("Xml to be parsed");

	       // NodeList nod=xml.getElementsByTagName("Park");
	       // System.out.println("Hello u have parsed");
		 
		 Document xml=XMLfunctions.XMLfromString(extraData);
		 int nod= xml.getElementsByTagName("Park").getLength();
		 System.out.println(nod);
		 ListView lv= (ListView)findViewById(R.id.listview);
	        String[] from = new String[] {"P_Name", "P_City"};
	                int[] to = new int[] { R.id.item1, R.id.item2 };
	           List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
	           for(int i = 0; i < nod; i++)
	           {    
	        	      HashMap<String, String> map = new HashMap<String, String>();
	        	       map.put("P_Name", "" + xml.getElementsByTagName("P_Name").item(i).getChildNodes().item(0).getNodeValue());
	        	       map.put("P_City", "" +xml.getElementsByTagName("P_City").item(i).getChildNodes().item(0).getNodeValue());
	        	      
	        	       fillMaps.add(map);
	           }
	        	       SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_item, from, to);
	        	     
	        	               lv.setAdapter(adapter);
		if (extras != null) {
			//TextView textView = new TextView(this);
			//textView.setText(extraData);
			//setContentView(textView);
			
		  //  data = extras.getString("com.activity.Key");
		}
		
	//setContentView(R.layout.list_item);
	}
};
